const express = require("express")
//引入数据库集合
const adminModel = require('../db/model/adminModel')

//引入权限控制校验中间件
const isLoginMiddel = require("../middleware/isLoginMiddel")

const route = express.Router()
//删除管理员
route.delete("/deleteAdmin",isLoginMiddel ,async (req, res) => {
    const {
        adminName
    } = req.query
    try {
        const deleteAdminResult = await adminModel.deleteOne({
            adminName
        })
        if (deleteAdminResult.deletedCount > 0) {
            return res.send({
                code: 10000,
                msg: "删除管理员" + adminName + "成功",
                data: null
            })
        }
        res.send({
            code: 10001,
            msg: "删除失败",
            data: null
        })

    } catch (e) {
        res.send({
            code: 10001,
            msg: "删除出现异常" + e.message,
            data: null
        })
    }
})
module.exports = route